<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:zanata="http://java.sun.com/jsf/composite/zanata"
  xmlns:h="http://java.sun.com/jsf/html"
  template="../WEB-INF/template/template.xhtml">

  <f:metadata>
    <f:event type="preRenderView" listener="#{identity.checkRole('admin')}"/>
  </f:metadata>

  <ui:define name="page_title">#{msgs['jsf.Statistics']}</ui:define>
  <ui:define name="center_content">

    <h:form styleClass="l--push-bottom-0">
      <a4j:jsFunction name="documentReady"
        limitRender="true"
        action="#{adminStatsAction.setDocumentReady(true)}"/>

      <a4j:jsFunction name="loadUsers" limitRender="true" render="userStats"/>
      <a4j:jsFunction name="loadProjects" limitRender="true" render="projectStats"/>
      <a4j:jsFunction name="loadVersions" limitRender="true" render="versionStats"/>
      <a4j:jsFunction name="loadDocuments" limitRender="true" render="documentStats"/>
      <a4j:jsFunction name="loadTextFlows" limitRender="true" render="textFlowStats"/>
      <a4j:jsFunction name="loadTranslations" limitRender="true" render="translationStats"/>
    </h:form>

    <script type="text/javascript">
      jQuery(document).ready(function () {
        documentReady();
        loadUsers();
        loadProjects();
        loadVersions();
        loadDocuments();
        loadTextFlows();
        loadTranslations();
      });
    </script>

    <div class="g--centered">
      <div class="g__item w--1-2-m w--3-8-l w--1-3 l--push-bottom-1">
        <p class="txt--meta l--push-all-0">
          <a href="/admin/home">
            #{msgs['jsf.Administration']}
          </a>
        </p>

        <h1 class="l--push-all-0">#{msgs['jsf.Statistics']}</h1>
        <h:panelGroup layout="block"  styleClass="panel l--pad-all-half l--push-v-half"  id="userStats">
          <i class="i i--users delta l--push-right-quarter"></i>
          <ui:fragment rendered="#{not adminStatsAction.documentReady}">
              <zanata:loader layout="inline"/>
          </ui:fragment>

          <ui:fragment rendered="#{adminStatsAction.documentReady}">
            #{msgs['jsf.TotalTranslators']} <span class="badge">#{adminStatsAction.totalTranslator}</span>

            <span class="l--push-h-quarter">
              #{msgs['jsf.TotalReviewers']} <span class="badge">#{adminStatsAction.totalReviewer}</span>
            </span>
          </ui:fragment>
        </h:panelGroup>

        <h:panelGroup layout="block"  styleClass="panel l--pad-all-half l--push-v-half" id="projectStats">
          <i class="i i--project delta l--push-right-quarter"></i>
          #{msgs['jsf.TotalProjects']}
          <ui:fragment rendered="#{not adminStatsAction.documentReady}">
            <zanata:loader layout="inline"/>
          </ui:fragment>

          <ui:fragment rendered="#{adminStatsAction.documentReady}">
            <span class="badge">#{adminStatsAction.totalProjectCount}</span>

            <div class="l--push-top-quarter">
              <span class="l--push-h-quarter txt--meta">
                #{msgs['jsf.Active']} <span class="badge--success">#{adminStatsAction.totalActiveProjectCount}</span>
              </span>

              <span class="l--push-h-quarter txt--meta">
                #{msgs['jsf.ReadOnly']} <span class="badge--warning">#{adminStatsAction.totalReadOnlyProjectCount}</span>
              </span>

               <span class="l--push-h-quarter txt--meta">
                #{msgs['jsf.Deleted']} <span class="badge--danger">#{adminStatsAction.totalObsoleteProjectCount}</span>
              </span>
            </div>
          </ui:fragment>
        </h:panelGroup>


        <h:panelGroup layout="block"  styleClass="panel l--pad-all-half l--push-v-half" id="versionStats">
          <i class="i i--version delta l--push-right-quarter"></i>
          #{msgs['jsf.Versions']}
          <ui:fragment rendered="#{not adminStatsAction.documentReady}">
            <zanata:loader layout="inline"/>
          </ui:fragment>

          <ui:fragment rendered="#{adminStatsAction.documentReady}">
            <span class="badge">#{adminStatsAction.totalProjectIterCount}</span>
            <div class="l--push-top-quarter">
              <span class="l--push-h-quarter txt--meta">
                #{msgs['jsf.Active']} <span class="badge--success">#{adminStatsAction.totalActiveProjectIterCount}</span>
              </span>

              <span class="l--push-h-quarter txt--meta">
                #{msgs['jsf.ReadOnly']} <span class="badge--warning">#{adminStatsAction.totalReadOnlyProjectIterCount}</span>
              </span>

               <span class="l--push-h-quarter txt--meta">
                #{msgs['jsf.Deleted']} <span class="badge--danger">#{adminStatsAction.totalObsoleteProjectIterCount}</span>
              </span>
            </div>
          </ui:fragment>
        </h:panelGroup>

        <h:panelGroup layout="block"  styleClass="panel l--pad-all-half l--push-v-half" id="documentStats">
          <i class="i i--document delta l--push-right-quarter"></i>
          #{msgs['jsf.TotalDocuments']}
          <ui:fragment rendered="#{not adminStatsAction.documentReady}">
            <zanata:loader layout="inline"/>
          </ui:fragment>

          <ui:fragment rendered="#{adminStatsAction.documentReady}">
            <span class="badge">#{adminStatsAction.totalDocuments}</span>
            <div class="l--push-top-quarter">
              <span class="l--push-h-quarter txt--meta">
                #{msgs['jsf.Active']} <span class="badge--success">#{adminStatsAction.totalActiveDocuments}</span>
              </span>

               <span class="l--push-h-quarter txt--meta">
                #{msgs['jsf.Deleted']} <span class="badge--danger">#{adminStatsAction.totalObsoleteDocuments}</span>
              </span>
            </div>
          </ui:fragment>
        </h:panelGroup>

        <h:panelGroup layout="block"  styleClass="panel l--pad-all-half l--push-v-half" id="textFlowStats">
          <i class="i i--translate delta l--push-right-quarter"></i>
          #{msgs['jsf.TotalTextFlows']}

          <ui:fragment rendered="#{not adminStatsAction.documentReady}">
            <zanata:loader layout="inline"/>
          </ui:fragment>

          <ui:fragment rendered="#{adminStatsAction.documentReady}">
            <span class="badge">#{adminStatsAction.totalTextFlows}</span>
            <div class="l--push-top-quarter">
              <span class="l--push-h-quarter txt--meta">
                #{msgs['jsf.Active']} <span class="badge--success">#{adminStatsAction.totalActiveTextFlows}</span>
              </span>

               <span class="l--push-h-quarter txt--meta">
                #{msgs['jsf.Deleted']} <span class="badge--danger">#{adminStatsAction.totalObsoleteTextFlows}</span>
              </span>
            </div>
          </ui:fragment>
        </h:panelGroup>

        <h:panelGroup layout="block"  styleClass="panel l--pad-all-half l--push-v-half" id="translationStats">
          <i class="i i--translate delta l--push-right-quarter"></i>
          #{msgs['jsf.TotalTextFlowTargets']}
          <ui:fragment rendered="#{not adminStatsAction.documentReady}">
            <zanata:loader layout="inline"/>
          </ui:fragment>

          <ui:fragment rendered="#{adminStatsAction.documentReady}">
            <span class="badge">#{adminStatsAction.totalTextFlowTargets}</span>
            <div class="l--push-top-quarter">
              <span class="l--push-h-quarter txt--meta">
                #{msgs['jsf.Active']} <span class="badge--success">#{adminStatsAction.totalActiveTextFlowTargets}</span>
              </span>

               <span class="l--push-h-quarter txt--meta">
                #{msgs['jsf.Deleted']} <span class="badge--danger">#{adminStatsAction.totalObsoleteTextFlowTargets}</span>
              </span>
            </div>

            <div class="l--push-top-half">
              <div class="l--push-all-quarter txt--meta">
                #{msgs['jsf.ApprovedOrTranslated']} <span class="badge--success">#{adminStatsAction.totalApprovedOrTranslatedTextFlowTargets}</span>
              </div>

              <div class="l--push-all-quarter txt--meta">
                #{msgs['jsf.RejectedOrFuzzy']} <span class="badge--unsure">#{adminStatsAction.totalRejectedOrFuzzyTextFlowTargets}</span>
              </div>

              <div class="l--push-all-quarter txt--meta">
                #{msgs['jsf.Untranslated']} <span class="badge">#{adminStatsAction.totalUntranslatedTextFlowTargets}</span>
              </div>
            </div>
          </ui:fragment>
        </h:panelGroup>
      </div>
    </div>

  </ui:define>
</ui:composition>
